From d15151335022604dc77578c44082a5320cf648be Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Tue, 26 Jul 2005 17:25:57 +0000 Subject: [PATCH] Implement xenbus_dev_error() and xenbus_dev_ok() functions for better error reporting using the store. Signed-off-by: Rusty Russel Signed-off-by: Christian Limpach --- .../drivers/xen/xenbus/xenbus_xs.c | 41 +++++++++++++++++-- linux-2.6-xen-sparse/include/asm-xen/xenbus.h | 7 ++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c index 1890ef4ed9..ccb64f84cc 100644 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c @@ -43,6 +43,7 @@ #define streq(a, b) (strcmp((a), (b)) == 0) +static char printf_buffer[4096]; static void *xs_in, *xs_out; static LIST_HEAD(watches); DECLARE_MUTEX(xenbus_lock); @@ -339,17 +340,49 @@ int xenbus_printf(const char *dir, const char *node, const char *fmt, ...) { va_list ap; int ret; - static char buffer[4096]; BUG_ON(down_trylock(&xenbus_lock) == 0); va_start(ap, fmt); - ret = vsnprintf(buffer, sizeof(buffer), fmt, ap); + ret = vsnprintf(printf_buffer, sizeof(printf_buffer), fmt, ap); va_end(ap); - BUG_ON(ret > sizeof(buffer)-1); - return xenbus_write(dir, node, buffer, O_CREAT); + BUG_ON(ret > sizeof(printf_buffer)-1); + return xenbus_write(dir, node, printf_buffer, O_CREAT); } +/* Report a (negative) errno into the store, with explanation. */ +void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...) +{ + va_list ap; + int ret; + unsigned int len; + + BUG_ON(down_trylock(&xenbus_lock) == 0); + + len = sprintf(printf_buffer, "%i ", -err); + va_start(ap, fmt); + ret = vsnprintf(printf_buffer+len, sizeof(printf_buffer)-len, fmt, ap); + va_end(ap); + + BUG_ON(len + ret > sizeof(printf_buffer)-1); + dev->has_error = 1; + if (xenbus_write(dev->nodename, "error", printf_buffer, O_CREAT) != 0) + printk("xenbus: failed to write error node for %s (%s)\n", + dev->nodename, printf_buffer); +} + +/* Clear any error. */ +void xenbus_dev_ok(struct xenbus_device *dev) +{ + if (dev->has_error) { + if (xenbus_rm(dev->nodename, "error") != 0) + printk("xenbus: failed to clear error node for %s\n", + dev->nodename); + else + dev->has_error = 0; + } +} + /* Takes tuples of names, scanf-style args, and void **, NULL terminated. */ int xenbus_gather(const char *dir, ...) { diff --git a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h index 2174251204..6d36ee7b86 100644 --- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h +++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h @@ -37,6 +37,7 @@ struct xenbus_device { char *subtype; char *nodename; struct device dev; + int has_error; void *data; }; @@ -97,6 +98,12 @@ int xenbus_printf(const char *dir, const char *node, const char *fmt, ...) * sprintf-style type string, and pointer. Returns 0 or errno.*/ int xenbus_gather(const char *dir, ...); +/* Report a (negative) errno into the store, with explanation. */ +void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt,...); + +/* Clear any error. */ +void xenbus_dev_ok(struct xenbus_device *dev); + /* Register callback to watch this node. */ struct xenbus_watch { -- 2.30.2